package com.yipinhouse.employee.app.appImpl;

import cn.hutool.core.bean.BeanUtil;
import com.yipinhouse.common.exception.HouseException;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.employee.client.BrokerInfoQueryClient;
import com.yipinhouse.employee.client.param.LoginParam;
import com.yipinhouse.employee.client.result.BrokerInfoResult;
import com.yipinhouse.employee.client.result.PromotionResultInfo;
import com.yipinhouse.employee.infra.model.BrokerInfo;
import com.yipinhouse.employee.service.BrokerInfoService;
import com.yipinhouse.employee.service.dto.BrokerInfoDto;
import com.yipinhouse.employee.service.dto.PromotionDto;
import com.yipinhouse.employee.service.dto.ShopBrokerInfoDto;
import com.yipinhouse.employee.service.param.LoginServiceParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
public class BrokerInfoQueryApiImpl implements BrokerInfoQueryClient {

    @Resource
    private BrokerInfoService brokerInfoService;

    /**
     * 员工登录信息验证
     *
     * @param param
     * @return
     */
    @Override
    public Result login(LoginParam param) {
        LoginServiceParam loginServiceParam = BeanUtil.copyProperties(param, LoginServiceParam.class);
        Integer login = brokerInfoService.login(loginServiceParam);
        return Result.getInstance(Integer.class).setData(login);
    }

    @Override
    public Result getBrokerInfo(Integer brokerId) {
        log.info("查询员工信息的入参id是=" + brokerId);
        BrokerInfoDto brokerInfoDto = brokerInfoService.getBrokerInfo(brokerId);
        BrokerInfoResult brokerInfoResult = BeanUtil.copyProperties(brokerInfoDto, BrokerInfoResult.class);
        return Result.getInstance(BrokerInfoResult.class).setMsg("查询成功").setCode(200).setData(brokerInfoResult);
    }

    /**
     * 升职，获取员工信息,修改员工职位
     * @param brokerId
     * @return
     */
    @Override
    public Result<PromotionResultInfo> promotion(Integer brokerId, Integer shopId) {
        log.info("员工Id：{}", brokerId);
        PromotionDto promotionDto = brokerInfoService.promotion(brokerId, shopId);
        PromotionResultInfo promotionResultInfo = BeanUtil.copyProperties(promotionDto, PromotionResultInfo.class);
        return Result.getInstance(PromotionResultInfo.class).setData(promotionResultInfo);
    }
}
